package edu.zjut.yzj.backend.service.impl.user.account;

import edu.zjut.yzj.backend.pojo.User;
import edu.zjut.yzj.backend.service.impl.utils.UserDetailsImpl;
import edu.zjut.yzj.backend.service.user.account.InfoService;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class InfoServiceImpl implements InfoService {


    @Override
    public Map<String, String> getinfo() {

        UsernamePasswordAuthenticationToken authenticationToken=
                (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
        UserDetailsImpl loginUser = (UserDetailsImpl) authenticationToken.getPrincipal();

        User user = loginUser.getUser();
        HashMap<String, String> map = new HashMap<>();

        map.put("error_message","success");
        map.put("id", user.getId().toString());
        map.put("username", user.getUsername());
        map.put("photo", user.getPhoto());
        return map;
    }
}
